package com.sto.stoapp.activity.scanner.inquiry;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

import com.sto.stoapp.db.StoDataBase;
import com.sto.stoapp.db.StoTableFieldName;
import com.sto.stoapp.db.manager.SiteFullManager;
import com.sto.stoapp.log.ExceptionLog;
import com.sto.stoapp.status.EnumTableNames;
import com.sto.stoapp.util.UnifiedStaticType;

public class InquiryQueryTable extends StoDataBase {

	private StoTableFieldName tableFieldName;
	// 未发送的状态
	private final String unsent = "未";

	private Boolean hasUnsend = false;
	private Context context;
	static InquiryQueryTable mInquiryQueryTable;


	public Boolean getHasUnsend() {
		return hasUnsend;
	}

	public static InquiryQueryTable getInstance(Context context) {
		if (mInquiryQueryTable == null)
			mInquiryQueryTable = new InquiryQueryTable(context);
		return mInquiryQueryTable;

	}

	public InquiryQueryTable(Context context) {
		super(context);
		this.context = context;
		tableFieldName = new StoTableFieldName();
	}

	/**
	 * 搜索全部数据
	 * 
	 * @return List<OnBusinessEntity>
	 */
	public List<HashMap<String, String>> queryAll(InquiryFieldSql inquirySql) {
		synchronized (UnifiedStaticType.DATABASE_SYNCHRONIZED) {
			List<HashMap<String, String>> data = new ArrayList<HashMap<String, String>>();

			/*
			 * if(inquirySql.getINQUIRYTABLENAME().equals(
			 * "table_salesman_order_back")){ data =
			 * queryOrderBackData(inquirySql); } else{
			 */
			// 搜索数据
			String INQUIRY_TABLE_head = "select " + tableFieldName.SCAN_DATE
					+ "," + tableFieldName.BAR_CODE_NUMBER + ","
					+ tableFieldName.SEND_STATE + " from ";
			String INQUIRY_TABLE_end = " where " + tableFieldName.SCAN_DATE
					+ " like ? " + " and " + tableFieldName.METADATA + "='1' "
					+ "order by " + tableFieldName.SCAN_TIME + " desc";
			data = getDataFromCursor(
					inquirySql,
					getCursor(
							UnifiedStaticType.READ_DATABASE,
							INQUIRY_TABLE_head
									+ inquirySql.getInquirytablename()
									+ INQUIRY_TABLE_end,
							inquirySql.getInquiryField()));
			// }
			return data;
		}
	}

	/**
	 * 查询订单打回表数据
	 * 
	 * @param inquirySql
	 * @return
	 */
	/*
	 * private List<HashMap<String, String>> queryOrderBackData(InquiryFieldSql
	 * inquirySql){ // 搜索数据 String INQUIRY_TABLE_head = "select " +
	 * tableFieldName.SCAN_DATE + "," + tableFieldName.DIFFERENT_FLAG + "," +
	 * tableFieldName.SEND_STATE + " from "; String INQUIRY_TABLE_end =
	 * " where " + tableFieldName.SCAN_DATE + " like ?"; List<HashMap<String,
	 * String>> data = getOrderBackDataFromCursor( inquirySql, getCursor(
	 * UnifiedStaticType.READ_DATABASE, INQUIRY_TABLE_head +
	 * inquirySql.getINQUIRYTABLENAME() + INQUIRY_TABLE_end,
	 * inquirySql.getInquiryField()));
	 * 
	 * return data; }
	 * 
	 * /** 获得订单打回表数据
	 * 
	 * @param inquirySql
	 * 
	 * @return
	 */
	/*
	 * private List<HashMap<String, String>> getOrderBackDataFromCursor(
	 * InquiryFieldSql fieldSql, final Cursor c) { List<HashMap<String, String>>
	 * list = new ArrayList<HashMap<String, String>>(); // 定义显示的内容包装
	 * 
	 * try { if (c != null) { if (c.moveToFirst()) { do { HashMap<String,
	 * String> map = new HashMap<String, String>(); // 定义Map集合，保存每一行数据
	 * 
	 * map.put(fieldSql.INQUIRYSTATUS, c.getString(c
	 * .getColumnIndex(tableFieldName.SEND_STATE)));
	 * map.put(fieldSql.INQUIRYCODE, c.getString(c
	 * .getColumnIndex(tableFieldName.DIFFERENT_FLAG)));
	 * map.put(fieldSql.INQUIRYDATE, c.getString(c
	 * .getColumnIndex(tableFieldName.SCAN_DATE))); list.add(map); // 保存了所有的数据行
	 * } while (c.moveToNext()); } closeCursor(c); } } catch (Exception e) {
	 * e.printStackTrace(); ExceptionLog.writeLog("getDataFromCursor",
	 * e.getMessage()); } closeDb(UnifiedStaticType.READ_DATABASE); return list;
	 * }
	 */

	private List<HashMap<String, String>> getDataFromCursor(
			InquiryFieldSql fieldSql, final Cursor c) {
		List<HashMap<String, String>> list = new ArrayList<HashMap<String, String>>(); // 定义显示的内容包装

		try {
			if (c != null) {
				if (c.moveToFirst()) {
					do {
						HashMap<String, String> map = new HashMap<String, String>(); // 定义Map集合，保存每一行数据
						String sendState = c.getString(c
								.getColumnIndex(tableFieldName.SEND_STATE));
						if (hasUnsend == false) {
							if (sendState.equals(unsent)) {
								hasUnsend = true;
							}
						}
						map.put(fieldSql.INQUIRYSTATUS, sendState);
						map.put(fieldSql.INQUIRYCODE,
								c.getString(c
										.getColumnIndex(tableFieldName.BAR_CODE_NUMBER)));
						map.put(fieldSql.INQUIRYDATE, c.getString(c
								.getColumnIndex(tableFieldName.SCAN_DATE)));
						list.add(map); // 保存了所有的数据行
					} while (c.moveToNext());
				}
				closeCursor(c);
			}
		} catch (Exception e) {
			e.printStackTrace();
			ExceptionLog.writeLog("getDataFromCursor", e.getMessage());
		}
		closeDb(UnifiedStaticType.READ_DATABASE);
		return list;
	}

	/**
	 * 统计发送或未发的元数据个数，条件为(1)
	 * 
	 * @author wxf
	 * 
	 * @param tablename
	 * @param date
	 * @param status
	 * @return
	 */
	public int StatisticsSentCount(String tablename, String date, String status) {
		int count = 0;
		String cmd = ("select count(*) from " + tablename + " where "
				+ tableFieldName.SCAN_DATE + " like ? and "
				+ tableFieldName.METADATA + "='1' and "
				+ tableFieldName.SEND_STATE + " = ?");
		Cursor c = getCursor(UnifiedStaticType.READ_DATABASE, cmd,
				new String[] { date + "%", status });
		if (c != null) {
			if (c.moveToFirst()) {
				count = c.getInt(0);
			}
			closeCursor(c);
		}
		// closeDb(UnifiedStaticType.READ_DATABASE);
		return count;
	}

	public String[] getCodeInquiryDetail(String tablename, String code, int item) {
		String sql = "select * from " + tablename + " where "
				+ tableFieldName.BAR_CODE_NUMBER + " = ? and "
				+ tableFieldName.METADATA + "='1'";
		Cursor cursor = getCursor(UnifiedStaticType.READ_DATABASE, sql,
				new String[] { code });
		return getCodeInquiryDetail(cursor, item);
	}

	/**
	 * 查询详情
	 * 
	 * @param tablename
	 * @param code
	 * @param date
	 * @param item
	 * @return
	 */
	public String[] getCodeInquiryDetail(String tablename, String code,
			String date, int item) {
		String sql = "select * from " + tablename + " where "
				+ tableFieldName.BAR_CODE_NUMBER + " = ? and "
				+ tableFieldName.SCAN_DATE + " like ? and "
				+ tableFieldName.METADATA + "='1'";
		Cursor cursor = getCursor(UnifiedStaticType.READ_DATABASE, sql,
				new String[] { code, date });
		return getCodeInquiryDetail(cursor, item);
	}

	/**
	 * 获取单号详情
	 * 
	 * @param tablename
	 * @param code
	 * @param date
	 * @param item
	 * @return
	 */
	private String[] getCodeInquiryDetail(Cursor cursor, int items) {
		String[] data = new String[13];
		EnumTableNames item = EnumTableNames.values()[items];
		for (int i = 0; i < data.length; i++)
			data[i] = "";
		if (cursor != null) {
			if (cursor.moveToNext()) {
				data[0] = "单号:"
						+ cursor.getString(cursor
								.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
				data[1] = "日期:"
						+ cursor.getString(cursor
								.getColumnIndex(tableFieldName.SCAN_DATE));
				data[2] = "时间:"
						+ cursor.getString(cursor
								.getColumnIndex(tableFieldName.SCAN_TIME));

				// data[3] = "网点编号:"
				// + cursor.getString(cursor
				// .getColumnIndex(tableFieldName.NET_CODE));

				String jobid = cursor.getString(cursor
						.getColumnIndex(tableFieldName.JOB_NUMBER));

				data[3] = "网点编号:"
						+ cursor.getString(cursor
								.getColumnIndex(tableFieldName.NET_CODE));
				data[4] = "工号:" + jobid;

				data[5] = "上传时间:\n"
						+ cursor.getString(cursor
								.getColumnIndex(tableFieldName.UPLOAD_TIME));
				data[12] = cursor.getString(cursor
						.getColumnIndex(tableFieldName.SEND_STATE)) + "发送";
				switch (item) {
				// 业务员-收件
				case STATUS_TABLE_SALESMAN_RECEIVE:
					data[6] = goodSType(cursor.getString(cursor
							.getColumnIndex(tableFieldName.FUNCTION_TYPE)));

					data[7] = "目的地:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));

					String scantype = cursor.getString(cursor
							.getColumnIndex(tableFieldName.EXPRESS_TYPE));

					if (scantype != null) {
						if (scantype.equals(" ")) {
							data[8] = "扫描类型:" + "普通件";
						} else if (scantype.equals("1")) {
							data[8] = "扫描类型:" + "24小时件";
						} else if (scantype.length() > 3) {
							data[8] = "扫描类型:" + "订单提取";
						}
					}
					data[9] = "寄手机号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.SEND_PHONE));
					data[10] = "收手机号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.REMARK_NAME));
					break;
				// 业务员-签收
				case STATUS_TABLE_SALESMAN_SIGN:
					data[6] = "签名:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.RECV_PERSON));

					break;
				// 问题件
				case STATUS_TABLE_PROBLEM:
					data[6] = "原因:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED5));
					break;
				// 订单提取
				case STATUS_TABLE_SALESMAN_ORDER_EXTRACT:
					data[6] = goodSType(cursor.getString(cursor
							.getColumnIndex(tableFieldName.FUNCTION_TYPE)));
					data[7] = "订单号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.REASON_NUMBER));

					break;
				// 订单打回
				case STATUS_TABLE_SALESMAN_ORDER_BACK:
					data[6] = "原因:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED5));
					/*
					 * data[6] = "订单编号:" + cursor.getString(cursor
					 * .getColumnIndex(tableFieldName.DIFFERENT_FLAG));
					 */
					break;
				// 服务点短信
				case STATUS_TABLE_SERVICE_SMS:
					data[6] = "服务点代码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.NEXT_STATION));
					data[7] = "服务点地址:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[8] = "服务电话:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.SEND_PERSON));
					data[9] = "手机号码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.REMARK_NAME));
					break;
				// 交接扫描
				case STATUS_TABLE_JOIN_SCAN:
					// data[6] = goodSType(cursor.getString(cursor
					// .getColumnIndex(tableFieldName.FUNCTION_TYPE)));

					break;

				// 扫描员-收件
				case STATUS_TABLE_SCANNING_RECEIVE:

					data[6] = goodSType(cursor.getString(cursor
							.getColumnIndex(tableFieldName.FUNCTION_TYPE)));

					data[7] = "收件员:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[8] = "目的地:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED4));
					data[9] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					break;
				// 扫描员-发件
				case STATUS_TABLE_SCANNING_SENDPIECE:
					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					data[8] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					break;
				// 扫描员-到件
				case STATUS_TABLE_SCANNING_REACHPIECE:
					data[6] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					break;
				// 扫描员-派件
				case STATUS_TABLE_SCANNING_ASSIGNPIECE:
					data[6] = "派件员:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					break;
				// 留仓件
				case STATUS_TABLE_STAY_WAREHOURSE:
					data[6] = "留仓人:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					break;
				// 装袋&发件
				case STATUS_TABLE_BAGGINGADNSENDPIECE:
					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					data[8] = "袋号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					break;
				// 装车发件
				case STATUS_TABLE_LOADCAR_SENDPIECE:
					data[7] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[0] = "单号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					break;
				// 发车扫描
				case STATUS_TABLE_SEND_CAR:
					data[0] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					data[6] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					break;
				// 到车扫描
				case STATUS_TABLE_RECEIVE_CAR:
					data[0] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					break;
				// 中转-到件
				case STATUS_TABLE_CENTER_REACHPIECE:
					data[7] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					data[6] = goodSType(cursor.getString(cursor
							.getColumnIndex(tableFieldName.FUNCTION_TYPE)));

					break;
				// 中转-发件
				case STATUS_TABLE_CENTER_SENDPIECE:

					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					data[8] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					data[9] = goodSType(cursor.getString(cursor
							.getColumnIndex(tableFieldName.FUNCTION_TYPE)));

					break;
				// 中转-留仓件
				case STATUS_TABLE_CENTER_STAY_WAREHOURSE:
					data[6] = "留仓人:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					break;
				// 中转-装袋发件
				case STATUS_TABLE_CENTER_BAGGINGADNSENDPIECE:
					data[6] = "袋号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));

					data[8] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					break;
				// 中转-装车发件
				case STATUS_TABLE_CENTER_LOADCAR_SENDPIECE:
					data[0] = "单号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					break;
				// 中转-发车扫描
				case STATUS_TABLE_CENTER_SEND_CAR:
					data[0] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					break;
				// 中转-到车扫描
				case STATUS_TABLE_CENTER_RECEIVE_CAR:
					data[0] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					break;
				// 航空-提货员-到包扫描
				case STATUS_TABLE_AVIATION_PICKER_PACKET:
					data[0] = "包号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					data[6] = "路由号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.NEXT_STATION));
					data[7] = "航班:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.REASON_NUMBER));
					break;
				// 航空-扫描员-到件扫描
				case STATUS_TABLE_AVIATION_SCAN_TO_PIECE:
					data[6] = "上一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					break;
				// 航空-扫描员-发件
				case STATUS_TABLE_AVIATION_SCAN_SEND:
					String nextS = cursor.getString(cursor
							.getColumnIndex(tableFieldName.NEXT_STATION));
					String nextSN = getNextStationName(nextS);

					if (!nextSN.equals("")) {
						data[6] = "下一站:" + nextSN;
					} else {
						data[6] = "下一站:" + nextS;
					}
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					data[8] = goodSType(cursor.getString(cursor
							.getColumnIndex(tableFieldName.FUNCTION_TYPE)));

					String des = cursor.getString(cursor
							.getColumnIndex(tableFieldName.USER_DEFINED3));

					String desN = getDestinationName(des);

					if (!nextSN.equals("")) {
						data[9] = "目的地:" + desN;
					} else {
						data[9] = "目的地:" + des;
					}
					// data[9] = "目的地:"
					// + cursor.getString(cursor
					// .getColumnIndex(tableFieldName.USER_DEFINED3));
					data[10] = "重量:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.WEIGHT));
					String route = cursor.getString(cursor
							.getColumnIndex(tableFieldName.REASON_NUMBER));
					if (route != null && route.length() > 0) {
						data[11] = "路由号："
								+ cursor.getString(cursor
										.getColumnIndex(tableFieldName.REASON_NUMBER));
					}
					break;
				// // 航空-扫描员-发件-指定路由发件
				// case 25:
				// data[5] = "路由号:"
				// + cursor.getString(cursor
				// .getColumnIndex(tableFieldName.REASON_NUMBER));
				// data[6] = "车辆ID:"
				// + cursor.getString(cursor
				// .getColumnIndex(tableFieldName.CARID_NUMBER));
				// data[7] = goodSType(cursor.getString(cursor
				// .getColumnIndex(tableFieldName.FUNCTION_TYPE)));
				// data[8] = "重量:"
				// + cursor.getString(cursor
				// .getColumnIndex(tableFieldName.WEIGHT));
				// break;
				// // TODO
				// 航空-扫描员-问题件
				case STATUS_TABLE_AVIATION_PROBLEM:
					data[6] = "原因:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED5));
					break;
				// 航空-扫描员-留仓件
				case STATUS_TABLE_AVIATION_STAY_WAREHOURSE:
					data[6] = "留仓人:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					break;
				// 航空-扫描员-包操作-装包
				case STATUS_TABLE_AVIATION_SCAN_PACKET_SEND:
					data[6] = "包号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					data[7] = "路由号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.REASON_NUMBER));
					break;
				// 航空-扫描员-包操作-发包
				case STATUS_TABLE_AVIATION_SCAN_SEND_BAG:
					// 航空-扫描员-包操作-到包
				case STATUS_TABLE_AVIATION_SCAN_ARRIVED_BAG:
					data[0] = "包号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					data[6] = "路由号:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.REASON_NUMBER));
					break;
				// 航空-扫描员-车辆操作-装车发件
				case STATUS_TABLE_AVIATION_LOADCAR_SENDPIECE:
					data[6] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAG_NUMBER));
					nextS = cursor.getString(cursor
							.getColumnIndex(tableFieldName.NEXT_STATION));
					nextSN = getNextStationName(nextS);
					if (!nextS.equals("")) {
						data[7] = "下一站:" + nextSN;
						// data[7] = "下一站:"
						// + cursor.getString(cursor
						// .getColumnIndex(tableFieldName.NEXT_STATION));
					} else {
						data[7] = "下一站:" + nextS;
					}
					des = cursor.getString(cursor
							.getColumnIndex(tableFieldName.USER_DEFINED3));
					desN = getDestinationName(des);
					if (!desN.equals("")) {
						data[8] = "目的地:" + desN;
					} else {
						data[8] = "目的地:" + des;
					}
					// data[8] = "目的地:"
					// + cursor.getString(cursor
					// .getColumnIndex(tableFieldName.USER_DEFINED3));

					break;
				// 航空-扫描员-车辆操作-发车
				case STATUS_TABLE_AVIATION_SEND_CAR:
					data[6] = "下一站:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.USER_DEFINED3));
					data[7] = "车辆ID:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.CARID_NUMBER));
					break;
				// 航空-扫描员-车辆操作-到车
				case STATUS_TABLE_AVIATION_RECEIVE_CAR:
					data[0] = "铅封条码:"
							+ cursor.getString(cursor
									.getColumnIndex(tableFieldName.BAR_CODE_NUMBER));
					break;
				default:
					break;
				}
			} else {
				data = null;
			}

			closeCursor(cursor);
		} else {
			data = null;
		}

		closeDb(UnifiedStaticType.READ_DATABASE);
		return data;
	}

	public boolean deleteInquiry(String tablename, String code, String date0) {
		synchronized (UnifiedStaticType.DATABASE_SYNCHRONIZED) {
			int ret = 0;
			StoTableFieldName tableFieldName = new StoTableFieldName();

			// 增加删除记录
			SimpleDateFormat sDateFormat = new SimpleDateFormat(
					"HH:mm:ss yyyy-MM-dd");
			String date = sDateFormat.format(new java.util.Date());
			String arrays[] = date.split(" ");

			SimpleDateFormat sDateFormat2 = new SimpleDateFormat(
					UnifiedStaticType.DATE_TIME_FORMAT);
			String date2 = sDateFormat2.format(new java.util.Date());
			String arrays2[] = date2.split(" ");
			SQLiteDatabase db = getSqliteDatabase(UnifiedStaticType.WRITE_DATABASE);
			try {

				ContentValues values = new ContentValues();
				values.put(tableFieldName.METADATA, "");
				values.put(tableFieldName.AUXOPCODE, "DELETED");
				values.put(tableFieldName.SCAN_DATE, arrays2[1]);
				values.put(tableFieldName.SCAN_TIME, arrays2[0]);
				values.put(tableFieldName.SCAN_DATE2, arrays[1]);
				ret = db.update(
						tablename,
						values,
						tableFieldName.BAR_CODE_NUMBER
								+ "=? and metadata=? and auxOpCode=? and send_state=? and scan_date=?",
						new String[] { code, "1", "NEW", "未", date0 });

			} catch (Exception ex) {
				ex.printStackTrace();
			} finally {
				closeDb(UnifiedStaticType.WRITE_DATABASE);
			}

			return ret > 0;
		}
	}

	// public boolean deleteInquiry(String tablename, String code, String date0)
	// {
	// int ret = 0;
	// synchronized (UnifiedStaticType.DATABASE_SYNCHRONIZED) {
	//
	// StoTableFieldName tableFieldName = new StoTableFieldName();
	//
	// SQLiteDatabase db = getSqliteDatabase(UnifiedStaticType.WRITE_DATABASE);
	//
	// // 增加删除记录
	// SimpleDateFormat sDateFormat = new SimpleDateFormat(
	// "HH:mm:ss yyyy-MM-dd");
	// String date = sDateFormat.format(new java.util.Date());
	// String arrays[] = date.split(" ");
	// /**
	// * 1.获取最后扫描的元数据信息
	// * 2.复制元数据插入一条记录
	// */
	// String sqlSelectInsert="insert into " + tablename
	// + "(command_type, pdauuid, auxopcode, role, exptype, "
	// + "metadata, next_station, bag_number, pack_number, "
	// + "scan_date, scan_time, function_type, express_type, "
	// + "bar_code_number, scanner_number, "
	// + "shift, reason_number, car_number, carID_number, remark_name, "
	// + "weight, input_weight, send_phone, "
	// + "unique_code, number, shipping, to_payment, payment, recv_person, "
	// + "send_person, upload_time, net_code, job_number, user_defined3, "
	// +
	// "user_defined4, user_defined5, send_state, different_flag, scan_date2) "
	// + "select command_type, pdauuid, replace(auxopcode, auxopcode," +
	// "'DELETED'" + ") as auxopcode, "
	// + "role, exptype, replace(metadata, metadata," +"''" +
	// ") as metadata, next_station, "
	// + "bag_number, pack_number, scan_date, replace(scan_time, scan_time, '"
	// + arrays[0] + "') as scan_time, function_type, express_type, "
	// +
	// "bar_code_number, scanner_number, shift, reason_number, car_number, carID_number, "
	// + "remark_name, weight, input_weight, send_phone, unique_code, number, "
	// +
	// "shipping, to_payment, payment, recv_person, send_person, upload_time, net_code, "
	// + "job_number, user_defined3, user_defined4, user_defined5, "
	// + "send_state, different_flag, replace(scan_date2, scan_date2, '"
	// + arrays[1]
	// + "') as scan_date2 from " + tablename + " where "
	// + "bar_code_number='" + code
	// +"' and metadata='1' and send_state='未' and scan_date='" + date0 +"'";
	//
	// SQLiteStatement statement = null;
	//
	// try {
	// db.beginTransaction();
	// statement = db.compileStatement(sqlSelectInsert);
	// // ret = statement.executeUpdateDelete();
	// ret = (int) statement.executeInsert();
	//
	// db = getSqliteDatabase(UnifiedStaticType.WRITE_DATABASE);
	// ContentValues values = new ContentValues();
	// values.put(tableFieldName.METADATA, "");
	//
	// if(ret > 0){
	// ret = db.update(tablename, values,
	// tableFieldName.BAR_CODE_NUMBER + "=" + code
	// + " and metadata=1", null);
	// }
	// db.setTransactionSuccessful();
	// }catch(Exception ex){
	// ex.printStackTrace();
	// }finally{
	// db.endTransaction();
	// if(statement != null){
	// statement.close();
	// }
	// closeDb(UnifiedStaticType.WRITE_DATABASE);
	// }
	//
	//
	//
	// }
	// return ret > 0;
	//
	// }

	private String goodSType(String keyChar) {
		String temp = "";
		if (!keyChar.equals("")) {
			temp = keyChar;
			switch (temp.charAt(0)) {
			case '1':
				temp = "物品类别:货样";
				break;
			case '2':
				temp = "物品类别:非货样";
				break;
			default:
				break;
			}
		}
		return temp;
	}

	/**
	 * 获得下一站名称
	 * 
	 * @author wxf
	 * 
	 * @param nextStationId
	 * @return
	 */
	public String getNextStationName(String nextStationId) {
		if (nextStationId == null || nextStationId.equals("")) {
			return "";
		}
		return SiteFullManager.getInstance(context).querySiteCodeName(
				nextStationId);
	}

	/**
	 * 获得目的地名称
	 * 
	 * @author wxf
	 * 
	 * @param destinationId
	 * @return
	 */
	public String getDestinationName(String destinationId) {
		if (destinationId == null || destinationId.equals("")) {
			return "";
		}
		return SiteFullManager.getInstance(context).querySiteCodeName(
				destinationId);
	}

}
